package com.clkj.sunhelp.mvp.policyinfo.policydetail;

import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.app.CustomApplication;
import com.clkj.sunhelp.bean.PolicyDetail;
import com.clkj.sunhelp.common.Config;
import com.clkj.sunhelp.common.IntentKey;
import com.clkj.sunhelp.mvp.base.BaseActivity;
import com.clkj.sunhelp.util.CommonUtil;
import com.clkj.sunhelp.util.ToastUtil;
import com.clkj.sunhelp.util.schedulers.SchedulerProvider;

/**
 * Created by Administrator on 2017/3/26.
 */

public class ActivityPolicyDetail extends BaseActivity implements PolicyDetailContract.View{

    private TextView tvPolicyTitle;
    private TextView tvPolicyTime;
    private WebView wvPolicyDetail;


    PolicyDetailContract.Presenter mPresenter;

    String mPolicyId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_policy_detail);
        initTitleWithRightTvOrIv(null,null,"政策法规详情",true,null,null);
        initData();
        assignView();
        initView();
        mPresenter = new PolicyDetailPresenter(this, SchedulerProvider.getInstance(), CustomApplication.getInstance().getHttpService());

        getPolicyDetail();
    }

    @Override
    public void initData() {
        mPolicyId = getIntent().getStringExtra(IntentKey.INTENT_KEY_POLICY_ID);
    }

    @Override
    public void assignView() {
        tvPolicyTitle = (TextView) findViewById(R.id.tv_policy_title);
        tvPolicyTime = (TextView) findViewById(R.id.tv_policy_time);
        wvPolicyDetail = (WebView) findViewById(R.id.wv_policy_detail);
    }

    @Override
    public void initView() {
        CommonUtil.initWebView(wvPolicyDetail);
    }

    @Override
    public void getPolicyDetail() {
        mPresenter.getPolicyDetail(mPolicyId);
    }

    @Override
    public void onGetPolicyDetailSuccess(PolicyDetail policyDetail) {
        tvPolicyTitle.setText(policyDetail.getFullHead());
        tvPolicyTime.setText("发布时间:"+policyDetail.getReleaseTime());
        wvPolicyDetail.loadDataWithBaseURL(Config.URL_BASE_IN_USE,policyDetail.getNewsContent(),"text/html","utf-8",null);
    }

    @Override
    public void onGetPolicyDetailError(String tip) {
        ToastUtil.showShort(this,tip);
    }

    @Override
    public void setPresenter(PolicyDetailContract.Presenter presenter) {

    }

    @Override
    public void showLoading() {
        showProgressDialog(false,null);
    }

    @Override
    public void dismissLoading() {
        dismissProgressDialog();
    }
}
